[Create a Namespace]
$ kubectl create namespace default-cpu-example

[Create the LimitRange in the default-cpu-example Namespace]
$ kubectl apply -f LimitRange_1.yaml --namespace=default-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults.yaml --namespace=default-cpu-example

Now if create a Pod in the default-cpu-example namespace, and any container in that Pod does not specify its own values for CPU request and CPU limit, then the control plane applies default values: a CPU request of 0.5 and a default CPU limit of 1.

[Create the Pod]
$ kubectl apply -f Pod_1.yaml --namespace=default-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod.yaml --namespace=default-cpu-example

[View the Pod's specification]
$ kubectl get pod default-cpu-demo --output=yaml --namespace=default-cpu-example
...
containers:
- image: nginx
  imagePullPolicy: Always
  name: default-cpu-demo-ctr
  resources:
    limits:
      cpu: "1"
    requests:
      cpu: 500m

The output shows that the Pod's only container has a CPU request of 500m cpu (which you can read as “500 millicpu”), and a CPU limit of 1 cpu. 
These are the default values specified by the LimitRange.


⦿ What if you specify a container's limit, but not its request ?

[Create the Pod]
$ kubectl apply -f Pod_2.yaml --namespace=default-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-2.yaml --namespace=default-cpu-example

[View the specification of the Pod that created]
$ kubectl get pod default-cpu-demo-2 --output=yaml --namespace=default-cpu-example
...
resources:
  limits:
    cpu: "1"
  requests:
    cpu: "1"

The output shows that the container's CPU request is set to match its CPU limit. 
Notice that the container was not assigned the default CPU request value of 0.5 cpu.


⦿ What if you specify a container's request, but not its limit ?

[Create the Pod]
$ kubectl apply -f Pod_3.yaml --namespace=default-cpu-example
$ kubectl apply -f https://k8s.io/examples/admin/resource/cpu-defaults-pod-3.yaml --namespace=default-cpu-example

[View the specification of the Pod that you created]
$ kubectl get pod default-cpu-demo-3 --output=yaml --namespace=default-cpu-example
...
resources:
  limits:
    cpu: "1"
  requests:
    cpu: 750m

However, the same container's CPU limit is set to 1 cpu, which is the default CPU limit for that namespace.


⦿ Motivation for default CPU limits and requests
If your namespace has a CPU resource quota configured, it is helpful to have a default value in place for CPU limit. 
Here are two of the restrictions that a CPU resource quota imposes on a namespace:
For every Pod that runs in the namespace, each of its containers must have a CPU limit.
CPU limits apply a resource reservation on the node where the Pod in question is scheduled. The total amount of CPU that is reserved for use by all Pods in the namespace must not exceed a specified limit.
When add a LimitRange:
If any Pod in that namespace that includes a container does not specify its own CPU limit.
The control plane applies the default CPU limit to that container.
The Pod can be allowed to run in a namespace that is restricted by a CPU ResourceQuota.

[Delete the namespace]
$ kubectl delete namespace default-cpu-example
